<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no">
		<title>绑定订单</title>
		<link rel="stylesheet" href="/static/css/style.css" />
		

	</head>

	<body>
		<div class="container" id="bind" v-cloak>

			<div class="form form-login form-getcash">

				<div class="unit">
					<i class="icon icon-dingdan"></i>
					<input type="number" placeholder="输入订单号" v-model="orderNo" />
				</div>

				<div class="unit">
					<a class="btn btn-block btn-round bg-primary" @click="doBind">
						确定
					</a>
					<p><i class="icon icon-tishi"></i>请下单后及时绑定订单，未绑订单不参与分红</p>

				</div>

			</div>

			<div class="list list-order" v-if="orderList.length > 0">
				<h2>最新未绑订单，请看到及时绑定</h2>

				
				<li v-for="(item,index) in orderList">
					<a>
						订单编号：<span>${item.order_sn}</span> <br /> 付款时间：
						<span>${item.create_time | formatTime}</span><br /> 预估分红：
						<em>${item.buyer_commission}</em><br /> 订单状态：

						<span>${item.order_status | status}</span>
					</a>

				</li>


			</div>

		</div>

	</body>
	<script src="/static/js/mui.min.js"></script>
	<script src="/static/js/vue.min.js"></script>
	<script src="/static/js/zepto.min.js"></script>
	<script src="/static/js/plugins/popup.js"></script>
	<script src="/static/js/plugins/scroll.js"></script>
	<script src="/static/js/plugins/pullrefresh.js"></script>
	<script type="text/javascript">
		var bind = new Vue({
			el: '#bind',
			delimiters: ['${', '}'],
			data: {
				
				orderList: [],
				orderNo: ""
			},
			mounted: function() {
				this.request();

			},

			methods: {
				doBack() {

				},

				request() {
					var self = this;

					$.post('/app/wxmp/user/orderWait', {}, function(res) {

						if(res.errno == 0) {
							self.orderList = res.data;

						} else {
							popup.prompt(res.errmsg);
						}
					});

				},
				doBind() {
					var self = this;
					if(!self.checkInt(self.orderNo)) {
						return popup.toast("请输入正确的订单编号");

					}

					$.post('/app/wxmp/user/bindOrder', {
						orderNo: self.orderNo
					}, function(res) {

						if(res.errno == 0) {
							return popup.prompt(res.data);

						} else {
							popup.prompt(res.errmsg);
						}
					});
				},
				checkInt(value) {
					var pattern = /(^([0-9]+)$)/;
					return pattern.test(value);

				},

			},
			filters: {
				formatTime(time) {
					var date = new Date(time);
					Y = date.getFullYear() + '-';
					M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
					D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
					h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
					m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
					s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
					return Y + M + D + h + m + s;
				},
				status(str) {
					var txt;
					switch(str) {
						case "12":
							txt = "已付款";
							break;
						case "3":
							txt = "已结算";
							break;
						case "13":
							txt = "已取消";
							break;
						default:
							break;
					}
					return txt;
				},

			}

		});
	</script>

</html>